package com.dk.controller;

import com.dk.em.Result;
import com.dk.pojo.SysAutoCodePart;
import com.dk.service.PartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("part")
@Api(tags = "规则组成服务")
@RefreshScope  //开启热更新
public class PartCodeController {

    @Autowired
    private PartService partService;

    /*查询*/
    @GetMapping
    @ApiOperation("查询接口")
    public Result getpart(){
        List<SysAutoCodePart>  partList= partService.getpart();
        return Result.OK().setData(partList);
    }

    /*增加*/
    @ApiOperation("增加接口")//error
    @PostMapping
    public Result insertpart(@RequestBody SysAutoCodePart part){
        partService.insertpart(part);
        return Result.OK();
    }
    /*根据id删除*/
    @ApiOperation("根据id删除")
    @DeleteMapping
    public Result deletepart(Long id){
        partService.deleteById(id);
        return Result.OK();
    }

    /*批量删除*/
    @ApiOperation("根据id批量删除")
    @DeleteMapping("deleteAllPart")
    public Result deleteAllPart(@RequestBody List<String> ids){
        partService.deleteAllPart(ids);
        return Result.OK();
    }

    /*修改*/
    @ApiOperation("修改接口")//error
    @PutMapping
    public Result updatePart(@RequestBody SysAutoCodePart part){
        partService.updatepart(part);
        return Result.OK();
    }

    /*List<SysAutoCodePart> selectByRuleId(@Param("ruleId") Long ruleId);

    String selectByPartTypeAndRuleId(@Param("partType") String partType, @Param("ruleId") Long ruleId);*/

    @GetMapping("selectByRuleId")
    public List<SysAutoCodePart> selectByRuleId(Long ruleId){
        List<SysAutoCodePart> partList = partService.selectByRuleId(ruleId);
        return partList;
    }

    @GetMapping("selectByPartTypeAndRuleId")
    public String selectByPartTypeAndRuleId(String partType,Long ruleId){
        String ruleId1 = partService.selectByPartTypeAndRuleId(partType, ruleId);
        return ruleId1;
    }

}
